package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.DayOrderBean;

import java.util.List;

public class InHospitalAdapter extends RecyclerView.Adapter<InHospitalAdapter.MyHolder> {

    Context context;
    List<DayOrderBean.InList> list;
    OnItemClickListenner onItemClickListenner;


    public InHospitalAdapter(Context context, List<DayOrderBean.InList> list, OnItemClickListenner onItemClickListenner){
        this.context=context;
        this.list=list;
        this.onItemClickListenner=onItemClickListenner;

    }
    @Override
    public InHospitalAdapter.MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_hospitalserver_gridelist, parent, false);

        return new MyHolder(inflate);
    }

    @Override
    public void onBindViewHolder(InHospitalAdapter.MyHolder holder, final int position) {

        holder.keyTv.setText(list.get(position).getFee_date());
        holder.payMoney.setText("￥"+list.get(position).getFee());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListenner.onRvItemClick(list.get(position).getFee(),list.get(position).getFee_date());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addData(List<DayOrderBean.InList> list){
        this.list=list;
        notifyDataSetChanged();

    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView keyTv;
        TextView payMoney;
        View itemView;
        public MyHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            keyTv=itemView.findViewById(R.id.keyTv);
            payMoney=itemView.findViewById(R.id.payMoney);

        }
    }

    public interface OnItemClickListenner{
        void onRvItemClick(String money,String date);
    }

}
